/**
 * 
 */
package com.googlecode.android_di;

import net.nycjava.skylight1.dependencyinjection.DependencyInjectingObjectFactory;

import com.google.inject.Module;

/**
 * @author Panxiaobo
 * 
 */
public abstract class DiModule implements Module {
    /* default */DependencyInjectingObjectFactory factory;

    /* default */void invokeConfigure() {
        configure();
    }

    protected <S, T extends S> void bindSingleton(Class<S> clz, Class<T> impl) {
        factory.registerSingletonImplementationClass(clz, impl);
    }

    protected <S, T extends S> void bindSingleton(Class<S> clz, String name, Class<T> impl) {
        factory.registerSingletonImplementationClass(clz, name, impl);
    }

    protected <S, T extends S> void bind(Class<S> clz, Class<T> impl) {
        factory.registerImplementationClass(clz, impl);
    }

    protected <S, T extends S> void bind(Class<S> clz) {
        factory.registerImplementationClass(clz, clz);
    }

    protected <S, T extends S> void bindSingleton(Class<S> clz) {
        factory.registerSingletonImplementationClass(clz, clz);
    }

    protected <S, T extends S> void bind(Class<S> clz, String name, Class<T> impl) {
        factory.registerImplementationClass(clz, name, impl);
    }

    protected <S, T extends S> void bindObject(Class<S> clz, String name, T obj) {
        factory.registerImplementationObject(clz, name, obj);
    }

    protected <S, T extends S> void bindObject(Class<S> clz, T obj) {
        factory.registerImplementationObject(clz, obj);
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    protected void bindConstant(String name, Object value) {
        Class clz = value.getClass();
        factory.registerConstant(clz, name, value);
    }

    protected abstract void configure();
}
